package daybook.io.args;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

import static daybook.Resources.RESOURCES_NAME;
import static daybook.Resources.Usages.*;

@Parameters(separators = "=", resourceBundle = RESOURCES_NAME)
public class TransactionArgs {
    @Parameter(names = {"--negate", "-n"}, arity = 0,
            descriptionKey = NEGATE_ACCOUNTS)
    private boolean negative = false;

    @Parameter(names = {"--accounts"}, variableArity = true,
            descriptionKey = ACCOUNTS)
    private List<String> accounts = null;

    @Parameter(names = "--startDate", arity = 1,
            descriptionKey = START_DATE,
            validateWith = LocalDateValidator.class,
            converter = LocalDateConverter.class)
    private LocalDate startDate = LocalDate.MIN;

    @Parameter(names = "--endDate", arity = 1,
            description = END_DATE,
            validateWith = LocalDateValidator.class,
            converter = LocalDateConverter.class)
    private LocalDate endDate = LocalDate.MAX;

    public boolean isNegative() {
        return negative;
    }

    public Optional<List<String>> getAccounts() {
        return Optional.ofNullable(accounts);
    }

    public LocalDate getStartDate() {
        return startDate;
    }

    public LocalDate getEndDate() {
        return endDate;
    }

    @Override
    public String toString() {
        return "TransactionArgs{" +
                "negative=" + negative +
                ", accounts=" + accounts +
                ", startDate=" + startDate +
                ", endDate=" + endDate +
                '}';
    }
}
